const isEmpty = (rule, value, callback) => {
  if (!value) {
    return callback(new Error('必须填写'))
  } else {
    return callback()
  }
}
const checkCardNo = (rule, value, callback) => {
  // 身份证号
  const regIdCard = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/

  let id = value
  let flag = true
  //转换大小写
  id = id.toUpperCase()
  let arrVerifyCode = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2]
  let Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
  // let Checker = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]
  if (id.length != 15 && id.length != 18) {
    flag = false
  }
  let Ai = id.length == 18 ? id.substring(0, 17) : id.slice(0, 6) + "19" + id.slice(6, 16)
  if (!/^\d+$/.test(Ai)) {
    flag = false
  }
  let yyyy = Ai.slice(6, 10),
    mm = Ai.slice(10, 12) - 1,
    dd = Ai.slice(12, 14)
  let d = new Date(yyyy, mm, dd),
    now = new Date()
  let year = d.getFullYear(),
    mon = d.getMonth(),
    day = d.getDate()
  if (year != yyyy || mon != mm || day != dd || d > now || year < 1800) {
    flag = false
  }
  let ret = 0
  for (let i = 0; i < 17; i++) {
    ret += Ai.charAt(i) * Wi[i]
  }
  Ai += arrVerifyCode[(ret %= 11)]
  if (id.length == 18 && id != Ai) {
    flag = false
  }
  if (!value) {
    return callback(new Error('必须填写'))
  } else if (!flag) {
    return callback(new Error('身份证号格式错误'))
  } else {
    return callback()
  }
}
const checkCity = (rule, value, callback) => {
  console.log(rule, 'rulerulerule')
  if (rule.no_check) {
    return callback()
  } else if (!value) {
    return callback(new Error('必须填写'))
  } else {
    return callback()
  }
}
// const checkMobile = (rule, value, callback) => {
//   console.log(value)
//   const regIdCard = /^1[3456789]\d{9}$/
//   if (!value) {
//     return callback(new Error('必须填写'))
//   } else if (value.length === 11 && !regIdCard.test(value)) {
//     return callback(new Error('手机号格式错误'))
//   } else {
//     return callback()
//   }
// }

export default {
  ruleValidate1: { // 社区工作者
    type: [{ required: true, message: '必须填写', trigger: 'change' }], // 人员类型
    name: [{ required: true, message: '必须填写', trigger: 'blur' }],
    card_no: [{ required: true, validator: checkCardNo, trigger: 'blur' }],
    phone: [{ required: true, message: '必须填写', trigger: 'blur' }],
    sex: [{ required: true, message: '必须填写', trigger: 'change' }],
    hunyin: [{ required: true, message: '必须填写', trigger: 'change' }], // 婚姻状况
    minzu: [{ required: true, message: '必须填写', trigger: 'change' }],
    work_condition: [{ required: true, message: '必须填写', trigger: 'change' }],
    birthday_date: [{ required: true, message: '必须填写', trigger: 'change' }],
    // id: [{ required: true, message: '必须填写', trigger: 'change' }],
    zzmm: [{ required: true, message: '必须填写', trigger: 'change' }],
    dwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 党委职务
    jwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 居委职务
    jwcy: [{ required: true, message: '必须填写', trigger: 'change' }], // 监委职务
    xhzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 协会职务
    tysb: [{ required: true, message: '必须填写', trigger: 'change' }], // 是否退役士兵
    js: [{ required: true, message: '必须填写', trigger: 'change' }], // 是否军嫂
    // tysbdx: [{ required: true, message: '必须填写', trigger: 'change' }], // 是否退役士兵定向
    // zsdx: [{ required: true, message: '必须填写', trigger: 'change' }], // 是否军嫂定向
    dbhzn: [{required: true, message: '必须填写', trigger: 'change' }], // 是否为低保或边缘低保户子女
    hj_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 户籍地址
    jt_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 家庭地址
    mgzp: [{ required: true, message: '必须上传', trigger: 'blur' }], // 免冠照片
    sfzzm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }], // 身份证正面
    sfzfm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }], // 身份证反面照片
    byyx: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }], // 毕业院校
    sxzy: [{ required: true, message: '必须填写', trigger: 'blur' }], // 所学专业
    zgxl: [{ required: true, message: '必须填写', trigger: 'change' }], // 最高学历
    xw: [{ required: true, message: '必须填写', trigger: 'change' }], // 学位
    bysj: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }], // 毕业时间
    // shgzs: [{ required: true, message: '必须填写', trigger: 'change' }], // 社会工作师职业资格
    rzsj: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }], // 入职时间
    rz_time: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }], // 任职时间
    // bscj: [{ required: true, message: '必须填写', trigger: 'change' }], // 笔试成绩
    // mscj: [{ required: true, message: '必须填写', trigger: 'change' }], // 面试成绩
    // qksgzg: [{ required: true, message: '必须填写', trigger: 'change' }] // 是否取得全科社工资格
  },
  ruleValidate2: { // 村工作者
    type: [{ required: true, message: '必须填写', trigger: 'change' }], // 人员类型
    name: [{ required: true, message: '必须填写', trigger: 'blur' }],
    card_no: [{ required: true, validator: checkCardNo, trigger: 'blur' }],
    phone: [{ required: true, message: '必须填写', trigger: 'blur' }],
    sex: [{ required: true, message: '必须填写', trigger: 'change' }],
    hunyin: [{ required: true, message: '必须填写', trigger: 'change' }], // 婚姻状况
    minzu: [{ required: true, message: '必须填写', trigger: 'change' }],
    zzmm: [{ required: true, message: '必须填写', trigger: 'change' }],
    dwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 党委职务
    jwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 居委职务
    jwcy: [{ required: true, message: '必须填写', trigger: 'change' }], // 监委职务
    hj_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 户籍地址
    jt_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 家庭地址
    mgzp: [{ required: true, message: '必须上传', trigger: 'blur' }], // 免冠照片
    sfzzm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }], // 身份证正面
    sfzfm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }], // 身份证反面照片
    byyx: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }], // 毕业院校
    sxzy: [{ required: true, message: '必须填写', trigger: 'blur' }], // 所学专业
    zgxl: [{ required: true, message: '必须填写', trigger: 'change' }], // 最高学历
    xw: [{ required: true, message: '必须填写', trigger: 'change' }], // 学位
    bysj: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }], // 毕业时间
    rzsj: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }], // 入职时间
    rz_time: [{ validator: isEmpty, required: true, message: '必须填写', trigger: 'blur' }] // 任职时间
  },
  ruleValidate3: { // 其他工作者
    type: [{ required: true, message: '必须填写', trigger: 'change' }], // 人员类型
    name: [{ required: true, message: '必须填写', trigger: 'blur' }],
    card_no: [{ required: true, validator: checkCardNo, trigger: 'blur' }],
    phone: [{ required: true, message: '必须填写', trigger: 'blur' }],
    sex: [{ required: true, message: '必须填写', trigger: 'change' }],
    hunyin: [{ required: true, message: '必须填写', trigger: 'change' }], // 婚姻状况
    minzu: [{ required: true, message: '必须填写', trigger: 'change' }],
    zzmm: [{ required: true, message: '必须填写', trigger: 'change' }],
    dwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 党委职务
    jwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 居委职务
    jwcy: [{ required: true, message: '必须填写', trigger: 'change' }], // 监委职务
    hj_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 户籍地址
    jt_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 家庭地址
    mgzp: [{ required: true, message: '必须上传', trigger: 'blur' }], // 免冠照片
    sfzzm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }], // 身份证正面
    sfzfm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }] // 身份证反面照片
  },
  ruleValidate4: { // 其他工作者
    type: [{ required: true, message: '必须填写', trigger: 'change' }], // 人员类型
    name: [{ required: true, message: '必须填写', trigger: 'blur' }],
    card_no: [{ required: true, validator: checkCardNo, trigger: 'blur' }],
    phone: [{ required: true, message: '必须填写', trigger: 'blur' }],
    sex: [{ required: true, message: '必须填写', trigger: 'change' }],
    hunyin: [{ required: true, message: '必须填写', trigger: 'change' }], // 婚姻状况
    minzu: [{ required: true, message: '必须填写', trigger: 'change' }],
    zzmm: [{ required: true, message: '必须填写', trigger: 'change' }],
    dwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 党委职务
    jwzw: [{ required: true, message: '必须填写', trigger: 'change' }], // 居委职务
    jwcy: [{ required: true, message: '必须填写', trigger: 'change' }], // 监委职务
    hj_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 户籍地址
    jt_address: [{ required: true, message: '必须填写', trigger: 'blur' }], // 家庭地址
    mgzp: [{ required: true, message: '必须上传', trigger: 'blur' }], // 免冠照片
    sfzzm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }], // 身份证正面
    sfzfm: [{ validator: isEmpty, message: '必须上传', trigger: 'blur' }] // 身份证反面照片
  }
}
